//
//  FKConfirmInviterVC.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/22.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKConfirmInviterVC.h"

@interface FKConfirmInviterVC ()

@property (weak, nonatomic) IBOutlet UIImageView *avatarView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *confirmBtn;
@property (weak, nonatomic) IBOutlet UIButton *errorBtn;

@end

@implementation FKConfirmInviterVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"确认邀请人";
    
    self.errorBtn.layer.borderColor = fkMainColor.CGColor;
    self.errorBtn.layer.borderWidth = 0.8;
    [self loadData];
}

- (IBAction)confirmBtnClicked:(UIButton *)sender
{
    sender.enabled = false;
    
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"type"] = @"2";
    param[@"invite_code"] = self.invite_code;
    [FKHttpTool postWithSuffix:@"m=Home&c=Login&a=inviteDeal" param:param success:^(FKBaseResult *result) {
        sender.enabled = true;
        if (result.isSuccess) {
            [SVProgressHUD showSuccessWithStatus:@"绑定邀请人成功"];
            [FKLoginTool changeRootVC];
//            [self.navigationController dismissViewControllerAnimated:true completion:nil];
        }
    } failure:^(NSError *error) {
        sender.enabled = true;
    }];
}

- (IBAction)errorBtnClicked:(UIButton *)sender
{
    fkPopVC;
}

#pragma mark - 网络请求
- (void)loadData
{
    NSMutableDictionary *param = [NSMutableDictionary dictionary];
    param[@"type"] = @"1";
    param[@"invite_code"] = self.invite_code;
    [FKHttpTool postWithSuffix:@"m=Home&c=Login&a=inviteDeal" param:param success:^(FKBaseResult *result) {
        if (result.isSuccess) {
            NSDictionary *invite_user_info = result.data[@"invite_user_info"];
            [self.avatarView sd_setImageWithURL:[NSURL URLWithString:invite_user_info[@"avatar"]] placeholderImage:kDefaultAvatar];
            self.nameLabel.text = invite_user_info[@"nickname"];
        }
    } failure:nil];
}

@end
